package com.example.nophase.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.example.nophase.Fragment.StaffMainHomeContentFragment;
import com.example.nophase.HomeActivity;
import com.example.nophase.R;
import com.example.nophase.activity.staff.AreaProjectActivity;
import com.example.nophase.activity.staff.ProjectActivity;
import com.example.nophase.base.BaseActivity;
import com.example.nophase.common.LoginManager;
import com.example.nophase.entity.SysUserVO;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ApplyForHomeActivity extends BaseActivity {


    @BindView(R.id.toolbar_btn)
    Button toolbarBtn;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.content_fragment)
    FrameLayout contentFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_apply_for_home);
        ButterKnife.bind(this);
        FragmentManager manager = getSupportFragmentManager();//初始化FragmentManager，获取v4包所支持的fragment
        //初始化FragmentTransaction
        FragmentTransaction transaction = manager.beginTransaction();
        transaction.
                add(R.id.content_fragment,
                        StaffMainHomeContentFragment.newInstance(ApplyForHomeActivity.this)).commit();
        setToolbar();
    }


    private void setToolbar() {

        toolbar.setTitle("");
        setSupportActionBar(toolbar);
        getSupportActionBar().setHomeButtonEnabled(true);
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setHomeAsUpIndicator(R.drawable.qmui_icon_topbar_back);
            toolbar.getBackground().setAlpha(255);
        }
       SysUserVO userVO = LoginManager.getUserInfo(this);
        toolbarBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                switch (userVO.getMoreInfo().getPosition()) {
                    case "区域业务员":
                        startActivity(new Intent(ApplyForHomeActivity.this, AreaProjectActivity.class));
                        break;
                    case "区域项目负责人":
                        startActivity(new Intent(ApplyForHomeActivity.this, AreaProjectActivity.class));
                        break;
                    case "职能中心员工":

                        startActivity(new Intent(ApplyForHomeActivity.this, ProjectActivity.class));
                        break;
                    case "总公司财务":
                        startActivity(new Intent(ApplyForHomeActivity.this, ProjectActivity.class));
                        break;
                    default:
                        startActivity(new Intent(ApplyForHomeActivity.this, ProjectActivity.class));

                        break;
                }


            }
        });
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {

            case android.R.id.home:
                this.finish();
                return true;

        }
        return super.onOptionsItemSelected(item);
    }

}
